home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
ulib
/
getext.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
1KB
|
64 lines
/***********************************************************************
* $Id: getext.c,v 0.80 1994/02/24 09:48:11 zhao Exp $
*
*. Copyright(c) 1993,1994 by T.C. Zhao
* All rights reserved.
*.
*
* return filename extension
***********************************************************************/
#if !defined(lint) && defined(F_ID)
char *id_gext = "$Id: getext.c,v 0.80 1994/02/24 09:48:11 zhao Exp $";
#endif
#include <stdio.h>
#include <string.h>
#include "ulib.h"
const char *
file_ext(const char *f)
{
const char *q;
if (!f || !*f)
return 0;
q = f + strlen(f) - 1;
while (q > f && *q != '.' && *q != '/')
q--;
return *q == '.' ? q + 1 : 0;
}
/******************************************************************
* given a complete filename, return the root part, similar to what
* :t does in csh
******************************************************************/
#define MAXBUF 3
const char *
file_tail(const char *f)
{
static char fbuf[MAXBUF][PATH_MAX];
static int cbuf;
char *p, *buf;
buf = fbuf[cbuf++];
strcpy(buf, f);
/* remove extension first */
if ((p = strchr(buf, '.')))
{
*p = '\0';
p = buf;
}
/* get tail */
if ((p = strrchr(buf, '/')))
*p++ = '\0';
cbuf %= MAXBUF;
return p ? p : buf;
}